/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef MULTIINDICEARRAY_H_INCLUDED
#define MULTIINDICEARRAY_H_INCLUDED

template<class T, int S> class MultiIndiceArray
{
public:
    typedef T type;
    type* ptr;

    MultiIndiceArray()
    {
        ptr = NULL;
    }

    MultiIndiceArray( type* _ptr)
    {
        ptr = _ptr;
    }

    MultiIndiceArray( const MultiIndiceArray &a)
    {
        ptr = a.ptr;
    }

    MultiIndiceArray & operator=( const MultiIndiceArray &a)
    {
        ptr = a.ptr;
        return *this;
    }

    type* & operator*()
    {
        return ptr;
    }

    type& operator[](unsigned int i)
    {
        return ptr[i];
    }
};

template<class T, int S1, int S2> class MultiIndiceArray< MultiIndiceArray<T, S1>, S2>
{
public:
    typedef typename MultiIndiceArray<T, S1>::type type;
    type* ptr;

    MultiIndiceArray()
    {
        ptr = NULL;
    }

    MultiIndiceArray( type* _ptr)
    {
        ptr = _ptr;
    }

    MultiIndiceArray( const MultiIndiceArray &a)
    {
        ptr = a.ptr;
    }

    MultiIndiceArray & operator=( const MultiIndiceArray &a)
    {
        ptr = a._ptr;
        return *this;
    }

    type* & operator*()
    {
        return ptr;
    }

    MultiIndiceArray<T,S1> operator[](unsigned int i)
    {
        return MultiIndiceArray<T,S1>( ptr + i*S2);
    }
};


#endif // MULTIINDICEARRAY_H_INCLUDED
